<template>
  <rx-dialog @handOk="handleReplyLinkup()" @cancel="cancel" :oktext="$ti18('rxForm.okBtn','确定')" order="top" btnalign="right">
    <a-form-model ref="form" :model="form" :rules="rules" class="container-a-form">
      <a-row>
        <a-col :span="24">
          <a-form-model-item :label="i18n('taskCheck.opinion','意见')" :labelCol="labelCol1" :wrapperCol="wrapperCol1"  prop="opinion">
            <a-textarea :placeholder="i18n('taskCheck.opinion','意见','write')" v-model="form.opinion"></a-textarea>
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :span="24">
          <a-form-model-item :label="i18n('taskCheck.attachment','附件')" :labelCol="labelCol1" :wrapperCol="wrapperCol1">
            <rx-attach-component v-model="form.files" ></rx-attach-component>
          </a-form-model-item>
        </a-col>
      </a-row>

    </a-form-model>
  </rx-dialog>
</template>

<script>
    import BpmPublicApi from '@/api/bpm/core/BpmPublicApi';
    import {BaseFormModel, RxDialog,Dialog,Util,RxAttachComponent} from '@lowcode/jpaas-common-lib';
    import BpmtaskApi from "@/api/bpm/core/bpmTask";

    export default {
        name: "task-commu-reply",
        components: {
            RxAttachComponent
        },
        mixins:[BaseFormModel],
        props:{
            taskId:{
                type:String
            }
        },
        data(){
            return {
                rules: {
                    opinion:[{ required: true, message: this.i18n('taskCheck.opinion','请填写意见','write'), trigger: 'change' }]
                },
                msgOptions:[],
                form:{
                    opFiles:"",
                    opinion:"",
                    msgType:[],
                    files:[]
                }


            }
        },
        created(){
            this.init();
        },
        methods:{
            i18n(name,text,key){
                return this.$ti18(name,text,"bpmTask",key);
            },
            init(){
                this.form.taskId=this.taskId;
                BpmPublicApi.getMessageHandler().then(res=>{
                    res.forEach((val)=> {
                        this.msgOptions.push({label:val.name,value:val.type})
                    })
                })
            },
            cancel(){
                Util.closeWindow(this,'cancel');
            },
            //回复沟通
            handleReplyLinkup() {
              this.form.opFiles = JSON.stringify(this.form.files);
              this.$refs.form.validate(valid => {
                if (!valid) {
                  return;
                }
                this.form.msgTypes = this.form.msgType.join(',');
                BpmtaskApi.replyLinkupTask(this.form).then(resp => {
                  if (resp.success) {
                    Util.closeWindow(this, 'ok');
                  }
                });
              })
            }
        }
    }
</script>

<style scoped>
.container-a-form{
    padding:10px 10px 0 0 ;
}
</style>